<?php

# PMB Online
# Aplikasi PMB Online untuk Pendaftaran Calon Mahasiswa di PT/PTS Indonesia
# 
# version 1.0
# class web
# file controllers/web.php
# created Jan 15, 2013 4:39:51 PM
# 
# (c)2012, arif.laksito@gmail.com

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Web extends CI_Controller {

    var $data = array();

    public function __construct() {
        parent::__construct();
    }

    public function index() {

        $this->output->enable_profiler(false);

        $this->data['jkel'] = $this->config->item('jns_kel');
        $this->data['agm'] = $this->config->item('agama');

        $this->load->model(array('jurusan', 'gelombang', 'csiswa', 'th_pmb'));
        $this->data['s1'] = $this->jurusan->get_by_program('S1');
        $this->data['d3'] = $this->jurusan->get_by_program('D3');

        $gel = $this->gelombang->get_gelombang_now();
        $tha = $this->th_pmb->get_tha_aktif();

        $post = array();
        $post = $this->input->post();

        if ($post) {
            if (isset($post['info']))
                $info = implode(',', $post['info']);
            else
                $info = "";

            $jur_d3 = $post['jur_d3'];
            $jur_s1 = $post['jur_s1'];
            unset($post['jur_d3']);
            unset($post['jur_s1']);
            unset($post['info']);

            $post['daftar_ol'] = 1;
            $post['id_gel'] = $gel['id_gel'];
            $post['nodaf'] = $this->csiswa->get_nodaf($tha['tha']);
            if ($info != '')
                $post['info'] = $info;

            $post['pilihan_jur'] = $jur_d3 . ',' . $jur_s1;

            #fn insert here..            
            if ($this->csiswa->insert($post)) {
                $this->data['sts'] = true;
                $this->data['msg'] = $this->csiswa->get_msg();
                $this->data['mhs'] = $this->csiswa->get($post['nodaf']);

                $this->data['page'] = 'daftar_success';
                $this->load->view('front', $this->data);
            } else {

                $this->data['sts'] = false;
                if (!isset($gel['id_gel']))
                    $this->data['msg'] = "Belum waktunya pendaftaran PMB, Data gelombang tidak ditemukan";
                else
                    $this->data['msg'] = $this->csiswa->get_msg();

                $post['jkel'] = (!empty($post['jkel'])) ? $post['jkel'] : 0;
                $post['status_nikah'] = (!empty($post['status_nikah'])) ? $post['status_nikah'] : "";
                $post['jur_d3'] = $jur_d3;
                $post['jur_s1'] = $jur_s1;
                $post['info'] = explode(',', $info);

                $this->data['post'] = $post;

                $this->data['page'] = 'daftar';
                $this->load->view('front', $this->data);
            }
        } else {

            $this->data['post'] = $post;

            $this->data['page'] = 'daftar';
            $this->load->view('front', $this->data);
        }
    }

    public function cetak() {

        $this->data['mhs'] = null;
        $post = array();
        $post = $this->input->post();
        if ($post) {
            $this->load->model('csiswa');
            $this->data['mhs'] = $this->csiswa->get($post['nodaf']);
        }

        $this->data['post'] = $post;
        $this->data['page'] = 'daftar_cetak';
        $this->load->view('front', $this->data);
    }

    public function check() {

        $this->load->model(array('csiswa', 'jurusan'));

        $post = array();
        $post = $this->input->post();
        if ($post) {            
            $this->data['res'] = $this->csiswa->check_lulus($post['nodaf'], $post['tgl_lahir']);
            $this->data['mhs'] = $this->csiswa->get($post['nodaf']);
            
            if(!empty($this->data['mhs']))
            $this->data['jur'] = $this->jurusan->get_by_id($this->data['mhs']['id_jurusan']);
        }

        $this->data['post'] = $post;
        $this->data['page'] = 'daftar_check';
        $this->load->view('front', $this->data);
    }

    public function cetak_bukti($nodaf) {
        $this->load->model('csiswa');

        $this->data['mhs'] = $this->csiswa->get($nodaf);
        $this->data['page'] = 'bukti_daftar';
        $this->load->view('cetak', $this->data);
    }

    public function cetak_biaya($nodaf) {
        $this->load->model(array('csiswa', 'biaya'));

        $this->data['mhs'] = $this->csiswa->get($nodaf);
        $this->data['d3'] = $this->biaya->get_by_gel_jur($this->data['mhs']['id_gel'], 'D3');
        $this->data['s1'] = $this->biaya->get_by_gel_jur($this->data['mhs']['id_gel'], 'S1');

        $this->data['page'] = 'biaya_cek';
        $this->load->view('cetak', $this->data);
    }

    public function rincian($nodaf) {
        $this->load->model(array('csiswa', 'biaya', 'jurusan'));

        $mhs = $this->csiswa->get($nodaf);
        $this->data['mhs'] = $mhs;
        $this->data['jur'] = $this->jurusan->get_by_id($mhs['id_jurusan']);
        $this->data['bia'] = $this->biaya->get_rincian($mhs['id_gel'], $mhs['id_jurusan']);

        $this->data['page'] = 'rincian_biaya';
        $this->load->view('cetak', $this->data);
    }

}